package cn.edu.stu.syllabus.adapters;

import android.graphics.drawable.GradientDrawable;
import android.support.annotation.Nullable;
import android.support.v4.content.ContextCompat;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.chad.library.adapter.base.BaseViewHolder;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;
import cn.edu.stu.syllabus.R;
import cn.edu.stu.syllabus.application.SyllabusApplication;
import cn.edu.stu.syllabus.base.BaseQuickClickAdapter;
import cn.edu.stu.syllabus.repository.oaFile.local.OaFileEntry;
import cn.edu.stu.syllabus.utils.ColorMapper;

/**
 * Created by daidaijie on 2017/3/23.
 */

public class OaFileAdapter extends BaseQuickClickAdapter<OaFileEntry, OaFileAdapter.ViewHolder> {

    ColorMapper mColorMapper;

    @Override
    protected ViewHolder createBaseViewHolder(View view) {
        return new ViewHolder(view);
    }

    public OaFileAdapter(List<OaFileEntry> data) {
        super(R.layout.item_oa_file, data);
        mColorMapper = new ColorMapper(OaFileEntry.class.getSimpleName());
    }

    @Override
    protected void convert(ViewHolder helper, OaFileEntry item) {
        GradientDrawable shape = (GradientDrawable) ContextCompat
                .getDrawable(SyllabusApplication.getContext(), R.drawable.bg_theme_picker);
        shape.setColor(mColorMapper.getTypeColor(item.getShortFileType()));
        helper.mFileTypeTextView.setBackground(shape);

        helper.mFileTypeTextView.setText(item.getShortFileType());
        helper.mFileNameTextView.setText(item.getFileName());
    }

    class ViewHolder extends BaseViewHolder {

        @Nullable
        @BindView(R.id.fileTypeTextView)
        TextView mFileTypeTextView;
        @Nullable
        @BindView(R.id.fileNameTextView)
        TextView mFileNameTextView;
        @Nullable
        @BindView(R.id.downloadImageView)
        ImageView mDownloadImageView;

        public ViewHolder(View view) {
            super(view);
            ButterKnife.bind(this, view);
        }
    }
}
